﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using KoPortal;
using KoPortal2;

/// <summary>
/// Summary description for WebServiceCommon
/// </summary>
[WebService(Namespace = "http://sp.korablik.local:88/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX
// , uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class WebServiceCommon : System.Web.Services.WebService
{

    #region Members
    private IContainer components = null;
    #endregion
    #region Constructors
    public WebServiceCommon ()
    {
        InitializeComponent(); 
    }
    #endregion Constructors
    #region Main Methods
    private void InitializeComponent()
    {
    }
    protected override void Dispose(bool disposing)
    {
        if (disposing && components != null)
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    #endregion Main Methods
    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
    #region GetMySqlSrvList
    [WebMethod(Description = "Get Item - GetMySqlSrvList_ByID", EnableSession = true)]
    public List<MySQLSrvList> GetMySqlSrvList_ByID(int parItemID)
    {
        List<MySQLSrvList> lst = new List<MySQLSrvList>();
        DataTable tbl = new DataTable("tblMySqlSrvList");
        Exception err =
            KoPortal2.Sys.Data.MySQL.DBKoLocal.GetMySqlSrvList_ByID(ref tbl, parItemID);
        if (err == null)
        {
            tbl.TableName = "tblMySqlSrvList";
            foreach (DataRow r in tbl.Rows)
            {
                lst.Add(new MySQLSrvList(
                      (int)r["id"]
                    , (string)r["name"]
                    , (string)r["ip"]
                    , (string)r["port"]
                    , (string)r["user"]
                    , (string)r["Pass"]
                    , (string)r["Db"]
                    , (bool)r["accept"]
                    , (int)r["id_object"])
                    );
            }
        }
        return lst;
    }
    [WebMethod(Description = "Get List - GetMySqlSrvList_ByParams", EnableSession = true)]
    public List<MySQLSrvList> GetMySqlSrvList_ByParams()
    {
        List<MySQLSrvList> lst = new List<MySQLSrvList>();
        DataTable tbl = new DataTable("tblMySqlSrvList");
        Exception err =
            KoPortal.System.Data.MySQL.DBKoLocal.GetMySqlSrvList(ref tbl);
        if (err == null)
        {
            tbl.TableName = "tblMySqlSrvList";
            foreach (DataRow r in tbl.Rows)
            {
                lst.Add(new MySQLSrvList(
                      (int)r["id"]
                    , (string)r["name"]
                    , (string)r["ip"]
                    , (string)r["port"]
                    , (string)r["user"]
                    , (string)r["Pass"]
                    , (string)r["Db"]
                    , (bool)r["accept"]
                    , (int)r["id_object"])
                    );
            }
        }
        return lst;
    }
    [WebMethod(Description = "Get List - GetMySqlSrvList", EnableSession = true)]
    public DataTable GetMySqlSrvList()
    {
        DataTable tbl = new DataTable("tblMySqlSrvList");
        Exception err =
            KoPortal.System.Data.MySQL.DBKoLocal.GetMySqlSrvList(ref tbl);
        tbl.TableName = "tblMySqlSrvList";
        return tbl;
    }
    [WebMethod(Description = "Get List - GetMySqlSrvList", EnableSession = true)]
    public List<MySQLSrvList> GetMySqlSrvList2()
    {
        return GetMySqlSrvList_ByParams();
    }
    [WebMethod(Description = "Get List - GetMySqlSrvList_ByDtFrom", EnableSession = true)]
    public DataTable GetMySqlSrvList_ByDtFrom(DateTime dtFrom)
    {
        DataTable tbl = new DataTable("tblMySqlSrvList");
        Exception err =
            KoPortal.System.Data.MySQL.DBKoLocal.GetMySqlSrvList(ref tbl);
        tbl.TableName = "tblMySqlSrvList";
        return tbl;
    }
    #endregion GetMySqlSrvList

    #region Suplier
    [WebMethod(Description = "Get List - Suplier", EnableSession = true)]
    public List<KoPortal2.Sys.Data.Axapta.Suplier> GetSuplier()
    {
        Exception err = null;
        List<KoPortal2.Sys.Data.Axapta.Suplier> list =
            new List<KoPortal2.Sys.Data.Axapta.Suplier>();
        err = KoPortal2.Sys.Data.Axapta.DBSuplier.GetDataObjList(ref list);
        return list;
    }
    [WebMethod(Description = "Get List - Suplier - By ID", EnableSession = true)]
    public List<KoPortal2.Sys.Data.Axapta.Suplier> GetSuplierByID(string id)
    {
        Exception err = null;
        List<KoPortal2.Sys.Data.Axapta.Suplier> list =
            new List<KoPortal2.Sys.Data.Axapta.Suplier>();
        err = KoPortal2.Sys.Data.Axapta.DBSuplier.GetDataObj_ByID(ref list, id);
        return list;
    }    
    #endregion Suplier
}
